package com.scuec.groupfive.Controller;

import com.scuec.groupfive.service.PostFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/post-favorite")
public class PostFavoriteController {
    @Autowired
    private PostFavoriteService postFavoriteService;

    @GetMapping("/total-count")
    public int getTotalFavoriteCount() {
        return postFavoriteService.getTotalFavoriteCount();
    }

    @GetMapping("/count/{postId}")
    public int getFavoriteCountByPostId(@PathVariable Long postId) {
        return postFavoriteService.getFavoriteCountByPostId(postId);
    }

    @GetMapping("/count-by-date")
    public int getFavoriteCountByDateRange(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        return postFavoriteService.getFavoriteCountByDateRange(startDate, endDate);
    }
}